<?php
session_start();//початок сесії

class Edit extends Controller 
{

	function Intro()
		{
			parent::Controller();	
		}//end method
	
	function index()
		{
			$this->general();
		}//end method

		
	function general()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;
			if(count($datas)<1)
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else
				{
					$data		= array();
					$data		= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);
					
					//отримання основної інформації профілю для поточного користучача
					$basicRs	= getRow('general_profile','*', "user_id='$userId'");
					//отримання статі
					$sex		= $basicRs['sex_id'];
					//отримання ким цікавиться
					$meetingList= explode(",",$basicRs['interested_in']);
					if(in_array('men',$meetingList))
						$menCheck	= 'checked';
					if(in_array('women',$meetingList))
						$womenCheck	= 'checked';
					//оримання стосунків
					$relation	= $basicRs['relation_id'];
					$lookingList= explode(',',trim($basicRs['looking_for_id'],","));
					$interestedList= explode(',',trim($basicRs['interested_in_id'],","));
					//підготовка дня народження
					$birthday	= $basicRs['birthday'];
					if($birthday !='')
						{
							$bdList		= explode("-", $birthday);
							$bd			= $bdList[0];
							$bm			= $bdList[1];
							$by			= $bdList[2];
						}
					else
						{
							$bd			= '-1';
							$bm			= '-1';
							$by			= '-1';
						}
					$bdVisible	= $basicRs['birthday_visibility_id'];
					$city		= $basicRs['city_symbol'];
					$politics	= $basicRs['political_id'];
					$religion	= $basicRs['religious_view'];
					//кінець базової інформації про профіль
					
					$data['birthDay']	= selectBox('birthday_day', createDay(),$bd);//створення днів народження в select box
					$data['birthMonth']	= selectBox('birthday_month', createMon(),$bm);//створення місяців народження в select box
					$data['birthYear']	= selectBox('birthday_year', createYear(),$by);//створення років народження в  select box
					$data['siteUrl']	= site_url();//store site url
					$data['userId']		= $userId;
					
					//створення статусу стосунків в  select box
					$res				= mysql_query("SELECT relation_id, relation FROM relation_status");
					$relationshipStatus	=array();
					$relationshipStatus[0]	= "--";
					if($res)
					while($rs=mysql_fetch_object($res))
						$relationshipStatus[$rs->relation_id]	= $rs->relation;
					$data['relationshipStatus']	= selectBox('relationship', $relationshipStatus,$relation,'class="select"');
					
					//створення статусу sex в  select box
					$res				= mysql_query("SELECT sex_id, sex FROM sex");
					$sexType	=array();
					$sexType[0]	= "--";
					if($res)
					while($rs=mysql_fetch_object($res))
						$sexType[$rs->sex_id]	= $rs->sex;
					$data['sexType']	= selectBox('sex', $sexType,$sex,'');
					
					if($basicRs['city']!='')
						$selectCity	= $basicRs['city'];
					else
						$selectCity	= '-1';
				
					$res				= mysql_query("SELECT city_symbol, city_name FROM city");
					$cityArr	=array();
					$cityArr[0]	= "--";
					if($res)
					while($rs=mysql_fetch_object($res))
						$cityArr[$rs->city_symbol]	= $rs->city_name;
					$data['city_select']	= selectBox('city_select',$cityArr,$selectCity,'');
					
					//створення select box для налаштувань відображення дня рародження
					$res				= mysql_query("SELECT birthday_visibility_id, birthday_option FROM birthday_visibility");
					$birthdayVisibility	=array();
					if($res)
					while($rs=mysql_fetch_object($res))
						$birthdayVisibility[$rs->birthday_visibility_id]	= $rs->birthday_option;
					$data['birthdayVisibility']	= selectBox('birthday_visibility', $birthdayVisibility,$bdVisible,'class="select"');
					
					//створення політичних поглядів в select box
					$res				= mysql_query("SELECT political_id,political_view FROM political_views");
					$politicalView		= array();
					$politicalView[0]	= "--";
					if($res)
					while($rs=mysql_fetch_object($res))
						$politicalView[$rs->political_id]	= $rs->political_view;
					$data['politicalView']	= selectBox('political_view', $politicalView, $politics, 'class="select"');
					
					//створення шукаю для check box
					$res		= mysql_query("SELECT looking_id, lookingfor FROM looking_for");
					$lookingFor	= "<tr>";
					$loop		= 1;
					if($res)
					while($rs=mysql_fetch_object($res))
						{
							//echo $rs->lookingfor;
							if(in_array($rs->looking_id,$lookingList))
								 $lookCheck	="checked";
							else
								$lookCheck	='';
							$lookingFor	.= "	<td><input name='meeting_for".$loop."' id='meeting_for".$loop."' type='checkbox' value='".$rs->looking_id."' ".$lookCheck."></td>
												<td style='padding: 5px;'><label for='meeting_for".$loop."' >".$rs->lookingfor."</label></td>";
							if($loop%2==0)
								$lookingFor .="</tr><tr>";
							$loop++;
						}
					$lookingFor 		.="</tr>";
					$data['lookingFor']	= $lookingFor;
					$data['totMeets']	= $loop-1;
					
					//interested in
					$res		= mysql_query("SELECT interested_id, interestedin FROM interested_in");
					$interestedIn	= "<tr>";
					$loop		= 1;
					if($res)
					while($rs=mysql_fetch_object($res))
						{
							//echo $rs->lookingfor;
							if(in_array($rs->interested_id,$interestedList))
								 $interestedCheck	="checked";
							else
								$interestedCheck	='';
							$interestedIn	.= "	<td><input name='meeting".$loop."' id='meeting".$loop."' type='checkbox' value='".$rs->interested_id."' ".$interestedCheck."></td>
													<td style='padding: 8px;'><label for='meeting".$loop."' >".$rs->interestedin."</label></td>";
							if($loop%2==0)
								$interestedIn .="</tr><tr>";
							$loop++;
						}
					$interestedIn 		.="</tr>";
					$data['interestedIn']	= $interestedIn;
					$data['totMeets2']	= $loop-1;
					
					$data['religion']		= $religion;
					$this->smartyextended->view('edit/general',$data);
				}
		}//end basic method
		

		
	function contacts()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;
			
			if(count($datas)<1)//якщо перевірка не вдалася
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else
				{
					$data		= array();
					$data		= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);
							
					$query	= "SELECT 
								mobile, land_line, address,
								website, icq, skype
								FROM contact_profile
								WHERE user_id='$userId'";
					$res	= mysql_query($query);
					if($res)
					while($rs=mysql_fetch_object($res))
						{
							$data['contact_mobile']			= $rs->mobile;
							$data['contact_landline']		= $rs->land_line;
							$data['contact_address']		= $rs->address;
							$data['contact_website']		= $rs->website;
							$data['contact_icq']			= $rs->icq;
							$data['contact_skype']			= $rs->skype;
						}//end while
						
					$this->smartyextended->view('edit/contacts',$data);
				}
		}//end contact()

		

	function personal()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;
			
			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else
				{
					$data		= array();
					$data		= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);
						
					$query	= "SELECT 
								activities, interests, favorite_music, favorite_tv_shows, favorite_movies, favorite_books, favorite_quotes,about_me
								FROM member_personal
								WHERE user_id='$userId'";
					$res	= mysql_query($query);
					if($res)
					while($rs=mysql_fetch_object($res))
						{
							$data['clubs']		= $rs->activities;
							$data['interests']	= $rs->interests;
							$data['music']		= $rs->favorite_music;
							$data['tv']			= $rs->favorite_tv_shows;
							$data['movies']		= $rs->favorite_movies;
							$data['books']		= $rs->favorite_books;
							$data['quote']		= $rs->favorite_quotes;
							$data['about_me']	= $rs->about_me;
						}
				
					$this->smartyextended->view('edit/personal',$data);
				}
		}	

		
	function education()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;
			
			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else
				{
					$data		= array();
					$data		= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);
					
					//create education year select box
					$data['education_1_year_select']	= selectBox('education_1_year',createSchoolYear());
					$data['education_2_year_select']	= selectBox('education_2_year',createSchoolYear());
					$data['education_3_year_select']	= selectBox('education_3_year',createSchoolYear());
					$data['education_4_year_select']	= selectBox('education_4_year',createSchoolYear());
						
					if($_POST['submit_education'])
						{
							if($this->storeEducation())
								$data['success']	= "Інформацію про освіту успішно збережено";
							else
								{
									$data['error']	= "Щось пішло не так! Інформацію про освіту невдалося зберегти";
								}//end else
						}//end submit
					
					$dat	= array_merge($data,$this->getEducation());
					//echo "<prev>";
					//print_r($dat);
					//echo "</prev>";
					$this->smartyextended->view('edit/education',$dat);
				}
		}

		
	function storeEducation()
		{
			$this->load_settings();
			global $userId,$now;
			
			$totalSchools	= $_POST['school_section_count'];
			for($i=1;$i<=$totalSchools;$i++)
				{
					if(trim($_POST['education_'.$i.'_school_name'])!='')
						$field1	= "school_name='".$_POST['education_'.$i.'_school_name']."'";
					else
						$field1	= "school_name=''";
						
					if($_POST['education_'.$i.'_year']>0)
						$field1	.= ",class_year='".$_POST['education_'.$i.'_year']."'";
					else
						$field1	.= ",class_year=''";
										
					if(trim($_POST['education_'.$i.'_concentration1_name'])!='')
						$field1	.= ",concentration1='".$_POST['education_'.$i.'_concentration1_name']."'";
					else
						$field1	.= ",concentration1=''";
					
					$schoolType	= 'education'.$i;
					//$field1		.= ",school_type='$schoolType'";
					
					if(IsRecordExist4Add('school_education','school_edu_id',"user_id='$userId' AND school_type='$schoolType'"))
						$result1	= updateRecords('school_education',$field1,"user_id='$userId' AND school_type='$schoolType'");
					else
						{
							if($field1!='')
								$field1 .=",user_id='$userId',school_type='$schoolType'";
							else
								$field1 ="user_id='$userId',school_type='$schoolType'";
							$result1	= insertRecord('school_education',$field1);
						}
				}
					
				$highSchool	= $_POST['highschool'];
				if(IsRecordExist4Add('education_profile','education_id',"user_id='$userId'"))
					$result2	= updateRecords('education_profile',"high_school='$highSchool'","user_id='$userId'");
				else
					$result2	= insertRecord('education_profile',"high_school='$highSchool',datestamp='$now',user_id='$userId'");
			if($result1 and $result2)
				return true;
			else
				return false;
		}//end storeEducation()

		
	function getEducation()
		{
			$this->load_settings();
			global $userId,$now;
			$datas		= array();
			$eduRs		= getRow("education_profile","high_school","user_id='$userId'");
			//create education year select box
			$datas['education_1_year_select']	= selectBox('education_1_year',createSchoolYear());
			$datas['education_2_year_select']	= selectBox('education_2_year',createSchoolYear());
			$datas['education_3_year_select']	= selectBox('education_3_year',createSchoolYear());
			$datas['education_4_year_select']	= selectBox('education_4_year',createSchoolYear());
			
			$query	= "SELECT 
						school_name,class_year,concentration1,school_type
						FROM school_education
						WHERE user_id='$userId'";
			$totSec	= getTotRec('school_edu_id',"school_education","user_id='$userId'");
			$res	= mysql_query($query);
			$i		= 1;
			if($res)
			while($rs=mysql_fetch_object($res))
				{
					if($rs->school_type=='education'.$i)
						{
							$datas['att_nothing_'.$i]	= '';
							$datas['att_college_'.$i]	= '';
							$datas['att_school_'.$i]	= '';
							
							$datas['education_'.$i]		= true;
							$datas['school_name_'.$i]	= $rs->school_name;	
								
							$datas['concentration1_'.$i]= $rs->concentration1;
							if($rs->class_year>0)
								$selectYear	= $rs->class_year;
							else
								$selectYear	= '-1';
								
							$datas['education_'.$i.'_year_select']	= selectBox('education_'.$i.'_year',createSchoolYear(),$selectYear);
						}
					$i++;
				}
			
			$datas['total_school']	= $totSec;
			$datas['high_school']	= $eduRs['high_school'];
			return $datas;
					
		}		

		
	function work()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;
			
			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else
				{
					$data		= array();
					$data		= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);

					$dat		= array_merge($data,$this->loadWorkSettings());
					if($_POST['submit_work'])
						{
							$dat['success']	= $this->storeWork();
						}//end submit
					$dat1	= array_merge($dat,$this->getWork());
					$this->smartyextended->view('edit/work',$dat1);
				}
		}//end work()

		
	function storeWork()
		{
			$this->load_settings();
			global $userId,$now;
			$result	= true;
			$totalJobs	= $_POST['work_section_count'];
			$j=0;
			for($i=1;$i<=$totalJobs;$i++)
				{
					if(trim($_POST['work_history_'.$i.'_company'])!='')
						$field1	= "employer='".$_POST['work_history_'.$i.'_company']."'";
					else
						$field1	= "employer=''";
						
					if(trim($_POST['work_history_'.$i.'_position'])!='')
						$field1	.= ",position='".$_POST['work_history_'.$i.'_position']."'";
					else
						$field1	.= ",position=''";
						
					if(trim($_POST['work_history_'.$i.'_description'])!='')
						$field1	.= ",description='".$_POST['work_history_'.$i.'_description']."'";
					else
						$field1	.= ",description=''";
											
					if($_POST['work_history_'.$i.'_city_select']!='-1')
						$field1	.= ",city='".$_POST['work_history_'.$i.'_city_select']."'";
					else
						$field1	.= ",city=''";


						
					if($_POST['work_history_'.$i.'_start_month_select']>0) 
						$field1	.= ",start_month='".$_POST['work_history_'.$i.'_start_month_select']."'";
					else
						$field1	.= ",start_month=''";
						
					if($_POST['work_history_'.$i.'_start_year_select']>0)
						$field1	.= ",start_year='".$_POST['work_history_'.$i.'_start_year_select']."'";
					else
						$field1	.= ",start_year=''";
						
					$curmonth= date("m");
					if(($_POST['work_history_'.$i.'_end_month_select']>0)  && ($curmonth>=$_POST['work_history_'.$i.'_end_month_select']))
						$field1	.= ",end_month='".$_POST['work_history_'.$i.'_end_month_select']."'";
					else
						$field1	.= ",end_month=''";
						


							if($_POST['work_history_'.$i.'_start_month_select']<=$_POST['work_history_'.$i.'_end_month_select'])
							$field1	.= ",end_year='".$_POST['work_history_'.$i.'_end_year_select']."'";
							else
							$field1	.= ",end_year=''";


				
						
					$jobType	= 'job'.$i;
					$field1		.= ",datestamp='$now'";
					if(IsRecordExist4Add('work_profile','work_id',"user_id='$userId' AND job_type='$jobType'"))
						{
						if($j==0)
							{
							$result1	= updateRecords('work_profile',$field1,"user_id='$userId' AND job_type='$jobType'");
							if($result1)
							$errmsg="Інформацію про роботу успішно збережено";
							else
							$errmsg="Щось пішло не так! Інформацію про роботу невдалося зберегти";
							}
						else
							{
							$errmsg="Помилка: Невірно вказаний часовий період";
							}
							
						}
					else
						{
							if($field1!='')
								$field1 .=",user_id='$userId',job_type='$jobType'";
							else
								$field1 ="user_id='$userId',job_type='$jobType'";
							if($j==0)
							{
							$result1	= insertRecord('work_profile',$field1);
							if($result1)
							$errmsg="Інформацію про роботу успішно збережено";
							else
							$errmsg="Помилка: Щось пішло не так! Інформацію про роботу невдалося зберегти";
							}
							else
							{
							$errmsg="Помилка: Часовий період вказано невірно";
							}
						}
					if(!$result1)
						$result	= false;
				}
				return $errmsg;
		}//end storeWork()

		
	function getWork()
		{
			$this->load_settings();
			global $userId,$now;
			$datas		= array();
			$datas		= $this->loadWorkSettings();
			$query	= "SELECT 
						employer,position,description,city,start_month,start_year,end_month,end_year,job_type
						FROM work_profile
						WHERE user_id='$userId' ORDER BY work_id";
			$totSec	= getTotRec('work_id',"work_profile","user_id='$userId'");
			$res	= mysql_query($query);
			$i		= 1;
			if($res)
			while($rs=mysql_fetch_object($res))
				{
					if($rs->job_type=='job'.$i)
						{
							$datas['job_'.$i]		= true;
							$datas['employer'.$i]	= $rs->employer;
							$datas['position'.$i]	= $rs->position;
							$datas['description'.$i]= $rs->description;
							
							if($rs->city!='')
								$selectCity	= $rs->city;
							else
								$selectCity	= '-1';
								
							if($rs->start_month!='')
								$selectSmonth	= $rs->start_month;
							else
								$selectSmonth	= '-1';
							if($rs->end_month!='')
								$selectEmonth	= $rs->end_month;
							else
								$selectEmonth	= '-1';
							if($rs->start_year!='')
								$selectSyear	= $rs->start_year;
							else
								$selectSyear	= '-1';
							if($rs->end_year!='')
								$selectEyear	= $rs->end_year;
							else
								$selectEyear	= '-1';
									
							$res		= mysql_query("SELECT city_symbol, city_name FROM city");
							$cityArr	= array();
							$cityArr[0]	= "--";
							if($res)
							while($rs=mysql_fetch_object($res))
								$cityArr[$rs->city_symbol]	= $rs->city_name;
								
							$workName	= 'work_history_'.$i;
							$datas['work_history_'.$i.'_city']			= selectBox('work_history_'.$i.'_city_select',$cityArr,$selectCity);
							$datas['work_history_'.$i.'_start_month']	= selectBox('work_history_'.$i.'_start_month_select',createMon(),$selectSmonth);
							$datas['work_history_'.$i.'_end_month']		= selectBox('work_history_'.$i.'_end_month_select',createMon(),$selectEmonth);
							$datas['work_history_'.$i.'_start_year']	= selectBox('work_history_'.$i.'_start_year_select',createWorkYear(),$selectSyear);
							$datas['work_history_'.$i.'_end_year']		= selectBox('work_history_'.$i.'_end_year_select',createWorkYear(),$selectEyear);
						}
					$i++;
				}
			
			if($totSec>0)
				$datas['total_jobs']	= $totSec;
			else
				$datas['total_jobs']	= 1;
			$datas['tot_jobs']	= $totSec;
			return $datas;
					
		}

		
	function loadWorkSettings()
		{
			$data	= array();
			$res		= mysql_query("SELECT city_symbol, city_name FROM city");
			$cityArr	= array();
			$cityArr[0]	= "--";
			if($res)
			while($rs=mysql_fetch_object($res))
				$cityArr[$rs->city_symbol]	= $rs->city_name;
				
			for($i=1;$i<=4;$i++)
				{
					$workName	= 'work_history'.$i;
					$data['work_history_'.$i.'_city']	= selectBox('work_history_'.$i.'_city_select',$cityArr);
					$data['work_history_'.$i.'_start_month']= selectBox('work_history_'.$i.'_start_month_select',createMon());
					$data['work_history_'.$i.'_end_month']	= selectBox('work_history_'.$i.'_end_month_select',createMon());
					$data['work_history_'.$i.'_start_year']	= selectBox('work_history_'.$i.'_start_year_select',createWorkYear());
					$data['work_history_'.$i.'_end_year']	= selectBox('work_history_'.$i.'_end_year_select',createWorkYear());
				}			
			return $data;
		}//end loadWorkSettings()
			

			
	function picture()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;
			
			if(count($datas)<1)
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else
				{
					$data		= array();
					$data		= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);

					//remove user photo both from database as well as the exact directory
					if($this->uri->segment(3)=='remove')
						{
							$picRs		= getRow('picture_profile', 'picture_path', "user_id='$userId'");
							$dirName	= './application/images/pictures/'.$userId;
							if($picRs['picture_path']=='')
								$data['error']	= 'Помилка: Фотографія не завантажена, для того щоб його можна було видалити';
							else
								{
									if(mysql_query("DELETE FROM picture_profile WHERE user_id='$userId'"))
										{
											removeFiles($dirName);
											$data['success']	= 'Фотографію успішно видалено';
										}
									else
										$data['error']	='Помилка: Щось пішло не так, під час видалення фото';
								}
						}//end image remove process
					elseif($this->uri->segment(3)=='upload')
						{

									$dirName	= './application/images/pictures/'.$userId;
									if(isFileExists($dirName))//if directory exist for this user, remove image
										recursive_remove_directory($dirName,true);
									else
										createDir($dirName);//else create new directory for this user
									
									//upload image settings
									$config['upload_path'] 		= $dirName."/";
									$config['allowed_types'] 	= 'gif|jpg|jpeg|png';
									$config['max_size']			= '4096';//in KB, 4 MB
									$config['encrypt_name']		= TRUE;

									//$config['max_width']		= '1024';// in pixels
									//$config['max_height']		= '768';//  in pixels
									//load upload library with new settings
									$this->load->library('upload', $config);
								
									if ( ! $this->upload->do_upload())//if file upload failed
										$data['error']	= $this->upload->display_errors();
									else// if file uplaod succeed
									{
										$data['success']	= "Фотографію успішно завантажено";
										$uploadedData		= $this->upload->data();
										$baseUrl			= base_url();
										$picturePath		= $dirName."/".$uploadedData['file_name'];
										
										//Thumb creation
										$thumb['image_library']		= 'GD2';
										$thumb['source_image'] 		= $picturePath;
										$thumb['create_thumb'] 		= FALSE;
										$thumb['maintain_ratio'] 	= TRUE;
										$thumb['width'] 			= 200;
										$thumb['height'] 			= 500;
										$this->load->library('image_lib', $thumb); 	
										
										if(!$this->image_lib->resize()) {
											$data['error']	= $this->image_lib->display_errors();
										} else {										
											$thumbPath		= base_url().$dirName."/".$uploadedData['raw_name']."".$uploadedData['file_ext'];
											image_crop(image_thumb($picturePath, 60, 60), 60, 60);	
										 }
							
										if(IsRecordExist4Add('picture_profile','picture_id',"user_id='$userId'"))
											updateRecords('picture_profile', "picture_path='$thumbPath', thumb_path='$thumbPath', datestamp='$now'","user_id='$userId'");
										else
											insertRecord('picture_profile', "user_id='$userId', picture_path='$thumbPath', thumb_path='$thumbPath', datestamp='$now'");
									}									
								
						}//end upload
					//get user photo
					$picRs					= getRow('picture_profile', 'picture_path', "user_id='$userId'");
					$data['picturePath']	= $picRs['picture_path'];	
					$data['currentPage']	= base_url();
					$this->smartyextended->view('edit/picture',$data);
				}
		}//end picture()

		
	function load_settings()
		{
			global $userId,$now, $adminName,$adminEmail,$siteName,$siteTitle;
			$this->load->model('common');
			
			$userId		= $this->session->userdata('user_id');
			$now		= $this->config->item('now');
			
			$siteVars	= $this->common->getSiteVars();
			$adminName	= $siteVars['adminName'];
			$adminEmail	= $siteVars['adminEmail'];
			$siteName	= $siteVars['siteName'];
			$siteTitle	= $siteVars['siteTitle'];

		}
	
}
?>